import myHttp from "@@/my-http";
import guardUrl from "@@/guard-url";

export default function () {

    const urlList: string = guardUrl.rbac.role.lst
    const urlAdd: string = guardUrl.rbac.role.add
    const urlDel: string = guardUrl.rbac.role.del

    let responseResult = ref<ResponseRecords>({
        records:[],
        total:0,
        msg:''
    })
    const loading = ref(false);

     function getRecords(params?: object) {
        loading.value = true
         myHttp.get(urlList, params).then(res => {
            responseResult.value.records = res.records
            responseResult.value.total = res.total
            responseResult.value.msg = res.msg
        }).finally(() => {
            loading.value = false
        })
    }

    function add(form: object) {
        loading.value = true
        myHttp.post(urlAdd, form).then(res => {
            ElMessage({type: 'success', message: res.msg,})
        }).finally(() => {
            loading.value = false
        })
    }
    function del(id: number[]) {
        //loading.value = true
        myHttp.get(urlDel, {id}).then(res=>{
            ElMessage({type: 'success', message: res.msg,})
        }).finally(() => {
            //loading.value = false
        })
    }


    return {responseResult,loading, getRecords, add, del}

}
